﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using System.Web.Routing;
using System.ComponentModel;

namespace OpenWeb.Dal.Services
{
  public class UnityControllerFactory : DefaultControllerFactory
  {
    private readonly IUnityContainer _container;

    public UnityControllerFactory(IUnityContainer container)
    {
      _container = container;
    }

    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
    {
      if (controllerType != null)
      {
        return _container.Resolve(controllerType) as IController;
      }
      return base.GetControllerInstance(requestContext, controllerType);
    }
  }
}
